﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;

namespace RemoteDesktopsTest
{
  static class AutomationElementSearch
  {
    static AutomationElementSearch()
    { }
    
    /// <summary>
    /// 
    /// </summary>
    /// <param name="searchElement"></param>
    /// <param name="id"></param>
    /// <returns></returns>
    public static AutomationElement FindElementById(AutomationElement searchElement, string id)
    {
      return searchElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, id));
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="searchElement"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    public static AutomationElement FindElementByName(AutomationElement searchElement, string name)
    {
      return searchElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, name));
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="searchElement"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    public static AutomationElementCollection FindElementsByType(AutomationElement searchElement, ControlType type)
    {
      return searchElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, type));
    }
  }
}
